package net.asfun.jvalog.resource;

import java.util.Collection;

import javax.jdo.Query;

import net.asfun.jvalog.vo.Pager;
import net.asfun.jvalog.common.Jdoer;
import net.asfun.jvalog.common.JdoerFactory;
import net.asfun.jvalog.entity.File;

public class FileDao {

	public static Collection<File> listAll(Pager pager) {
		Jdoer<File> jdf = JdoerFactory.jdoFile;
		pager.setTotal(jdf.all().size());
		Query q = jdf.prepareQuery();
		q.setRange(pager.getStart(), pager.getEnd());
		return jdf.more(q);
	}

	public static File getByName(String name) {
		Jdoer<File> jdf = JdoerFactory.jdoFile;
		Query q = jdf.prepareQuery();
		q.setFilter("name == aname");
		q.declareParameters("String aname");
		return jdf.unique(q, name);
	}

}
